package com.manage.mynet.action;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.alibaba.fastjson.JSONObject;
import com.manage.mynet.entity.CreateAudioVo;
import com.manage.mynet.service.CreateAudioService;

@Controller
public class CreateAudioAction {

	private static Logger logger = Logger.getLogger(CreateAudioAction.class);

	private CreateAudioService createAudioService;//创建createAudioService类

	@Resource(name = "createAudioService")
	public void setCreateAudioService(CreateAudioService createAudioService) {
		this.createAudioService = createAudioService;//获取createAudioService对象
	}

	@RequestMapping(value = "/audio/add.do")
	public String add(CreateAudioVo vo, HttpServletRequest request, HttpServletResponse response) {
		response.setContentType("text/html;charset=utf-8");
		boolean resultFlag = false;
		String resultInfo = "";
		
		
		String param1 = request.getParameter("param1");
		String param2 = request.getParameter("param2");
		String param3 = request.getParameter("param3");//获取页面参数
		
		//TODO
		logger.info("后期要删除日志-----------------------------------------------------");
		logger.info("参数param1显示：" + param1);
		logger.info("参数param2显示：" + param2);
		logger.info("参数param3显示：" + param3);//显示参数
		
		
		String validStr = validAddParam(vo);//
		Object resultVo = null;
		if ("".equals(validStr)) {
			try {
				//调用后台生成音频等等一系列逻辑，返回成功生成音频所需要的一切参数
				resultVo = createAudioService.addCreateAudioVo(vo);
				resultFlag = true;
				resultInfo = "操作成功";
			} catch (Exception e) {
				logger.error("add error", e);
				resultFlag = false;
				resultInfo = "操作失败";
			}
		} else {
			resultFlag = false;
			resultInfo = validStr;
		}
		JSONObject json = new JSONObject();
		json.put("resultFlag", resultFlag);
		json.put("resultInfo", resultInfo);
		if(null != resultVo){
			json.put("resultVo", resultVo);
		}
		
		logger.info("测试日志打印：---后期要删除该语句:" + json.toString());
		
		try {
			response.getWriter().write(json.toString());
		} catch (Exception e) {
			logger.error("ajax json return error", e);
		}
		return null;
	}

	private String validAddParam(CreateAudioVo vo) {

		// 用户 输入参数验证
		//return "测试生成失败";//
		//成功
		return "";
	}

}
